package com.shuw.com.beingfortextproject.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.shuw.com.beingfortextproject.R;

import java.util.List;

/**
 * Created by ${cs} on 2018/4/9.
 */

public class TabAdapter extends FragmentPagerAdapter {

	private List<String> titles;
	private List<Fragment> fragments;
	private Context mContext;
	private int bgIcon[]  ={R.drawable.dati_bgicon_selector,R.drawable.liveroom_bgicon_selector,R.drawable.tv_live_selector};

	public TabAdapter(List<String> titles, List<Fragment> fragments, FragmentManager fm,Context context) {
		super(fm);
		this.titles = titles;
		this.fragments = fragments;
		this.mContext = context;
	}


	@Override
	public int getCount() {
		return fragments.size();
	}

	@Override
	public Fragment getItem(int position) {
		return fragments.get(position);
	}


	public View getTabView(int position){
		View view = LayoutInflater.from(mContext).inflate(R.layout.tab_item2_layout,null);
		TextView title = view.findViewById(R.id.tab_title);
		Drawable drawable = mContext.getResources().getDrawable(bgIcon[position]);
		title.setCompoundDrawablesWithIntrinsicBounds(null, drawable,null,null);//设置icon
		title.setText(titles.get(position));
		return view;
	}
}
